package com.android.topview.watermelon.database

import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import androidx.room.migration.Migration
import androidx.sqlite.db.SupportSQLiteDatabase
import com.android.topview.watermelon.account.dao.AccountDao
import com.android.topview.watermelon.account.entity.Account

@Database(version = 1,entities = [Account::class],exportSchema = false)
abstract class AppDatabase:RoomDatabase() {
    abstract fun accountDao():AccountDao

    companion object{
        private var instance:AppDatabase? = null

        @Synchronized
        fun getDatabase(context:Context):AppDatabase{
            instance?.let {
                return it
            }
            return Room.databaseBuilder(context.applicationContext,AppDatabase::class.java,"app_database").build().apply {
                instance = this
            }

        }



    }
}